<template>
  <div class="city">
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <!--步骤四：letter传递给List-->
    <city-list :hot="hotCities" :city="cities" :letter="letter"></city-list>
    <!--步骤二：City组件监听change事件，绑定方法-->
    <city-alphabet :cities="cities" @change="handleLetterChange"></city-alphabet>
  </div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/CityHeader'
import CitySearch from './components/CitySearch'
import CityList from './components/CityList'
import CityAlphabet from './components/CityAlphabet'
export default {
  name: 'City',
  data(){
    return{
      hotCities:[],
      cities:{},
      // 步骤五：接收letter
      letter: '',
    }
  },
  components:{
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet,
  },
  mounted(){
    this.getCityInfo()
  },
  methods:{
    getCityInfo(){
      axios.get('/travel/index.php/Home/city/index').then(
        this.getCityInfoSucc
      )
    },
    getCityInfoSucc(res){
      console.log(res)
      res=res.data
      // console.log(res)
      if(res.ret && res.data){
        // const data = res.data
        this.hotCities = res.data.hotCities
        this.cities = res.data.cities
        this.alphabetList = res.data.alphabetList
      }
    },
    // City组件
    // 步骤三：接收参数letter，转化给List组件
    handleLetterChange(letter){
        // console.log(letter)
        this.letter = letter
    },
  }
}
</script>

<style lang="stylus" scoped>

</style>